<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>图片列表</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">

    <!-- 上传图片框样式，不使用上传组件可以删除此样式 -->
    <style>
        .avatar-uploader .el-upload {
            border: 1px dashed #d9d9d9;
            border-radius: 6px;
            cursor: pointer;
            position: relative;
            overflow: hidden;
        }

        .avatar-uploader .el-upload:hover {
            border-color: #409EFF;
        }

        .avatar-uploader-icon {
            font-size: 28px;
            color: #8c939d;
            width: 150px;
            height: 70px;
            line-height: 150px;
            text-align: center;
        }

        .avatar {
            width: 150px;
            height: 70px;
            display: block;
        }

    </style>
</head>
<body class="hold-transition">
<div id="app">


    <div class="filter-container">
        <!--查询表单-->
        <el-form :inline="true">
            <el-form-item label="相册名称">
                <el-input v-model="searchMap.title" placeholder="相册名称" class="filter-item"></el-input>
            </el-form-item>
            <!--          <el-form-item label="相册封面">
            <el-input v-model="searchMap.image" placeholder="相册封面" class="filter-item" ></el-input></el-form-item>
                      <el-form-item label="图片列表">
            <el-input v-model="searchMap.imageItems" placeholder="图片列表" class="filter-item" ></el-input></el-form-item>-->
            <el-button class="dalfBut" @click="fetchData()">查询</el-button>
            <el-button type="primary" class="butT" @click="formVisible=true;pojo={}">新增</el-button>
        </el-form>
    </div>
    <!--  <div class="content-header">
          <h1>管理<small>album管理</small></h1>
          <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
              <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
              <el-breadcrumb-item>管理</el-breadcrumb-item>
              <el-breadcrumb-item>album管理</el-breadcrumb-item>
          </el-breadcrumb>
      </div>-->

    <div class="app-container">
        <div class="box">
            <div v-for="img in imageItems" class="filter-container" style="border: 1px black solid;width: 160px">
                <img :src="img.url" width="150px" height="150px">
                <br/>
                <span> <el-button @click="dele(img)" size="mini" type="danger"
                                  size="small">删除</el-button></span>
            </div>
        </div>
    </div>


</div>
</body>
<script src="/js/vue.js"></script>
<script src="/js/axios.js"></script>
<script src="/js/elementui.js"></script>
<script src="/js/util.js"></script>
<script>
    new Vue({
        el: '#app',
        data() {
            return {
                tableData: [],
                currentPage: 1,
                total: 10,
                size: 10,
                searchMap: {},
                pojo: {},
                formVisible: false,
                imageUrl: '',
                imageItems: []
            }
        },
        created() {
            var id = getQueryString('id');
            axios.get(`/album/findById.do?id=${id}`).then(response => {
                this.imageItems = JSON.parse(response.data.imageItems);//[{},{},{}]
                this.imageUrl = this.pojo.image //显示图片  如页面有图片上传功能放开注释
            })
            this.fetchData();
        },
        methods: {
            fetchData() {
                axios.post(`/album/findPage.do?page=${this.currentPage}&size=${this.size}`, this.searchMap).then(response => {
                    this.tableData = response.data.rows;//
                    this.total = response.data.total;
                });
            },
            save() {
                // this.pojo.image= this.imageUrl; //如页面有图片上传功能放开注释
                axios.post(`/album/${this.pojo.id == null ? 'add' : 'update'}.do`, this.pojo).then(response => {
                    this.fetchData(); //刷新列表
                    this.formVisible = false;//关闭窗口
                });
            },
            edit(id) {
                this.formVisible = true // 打开窗口
                // 调用查询
                axios.get(`/album/findById.do?id=${id}`).then(response => {
                    this.pojo = response.data;
                    // this.imageUrl=this.pojo.image //显示图片  如页面有图片上传功能放开注释
                })
            },
            dele(img) {

                this.imageItems.splice(img,1);
               /* this.$confirm('确定要删除此记录吗?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    axios.get(`/album/delete.do?id=${id}`).then(response => {
                        this.fetchData(); //刷新列表
                    })
                })*/
            },
            list(id) {
                location.href = `spec.html?id=` + id

            },
            //****图片上传相关代码  如页面有图片上传功能放开注释 ****
            handleAvatarSuccess(res, file) {
                this.imageUrl = file.response;
            },
            beforeAvatarUpload(file) {
                const isJPG = file.type === 'image/jpeg';
                const isLt2M = file.size / 1024 / 1024 < 2;

                if (!isJPG) {
                    this.$message.error('上传头像图片只能是 JPG 格式!');
                }
                if (!isLt2M) {
                    this.$message.error('上传头像图片大小不能超过 2MB!');
                }
                return isJPG && isLt2M;
            }
        }
    })
</script>
</html>
